package com.project.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.daos.zt_StallMapper;
import com.project.entity.Order1;
import com.project.entity.Stall;
import com.project.entity.Vehicle;
import com.project.service.StallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
@Service
@Transactional
public class StallServiceImpl implements StallService {
    @Autowired
    private zt_StallMapper zt_stallMapper;

    @Override
    public PageInfo<Stall> zt_selStallAll(Integer curentPage, Integer pageSize,String stall_size,String stall_code) {
        PageHelper.startPage(curentPage, pageSize);
        List<Stall> l = zt_stallMapper.selectStallAll(stall_size, stall_code);
        PageInfo<Stall> pageInfo = new PageInfo(l);
        return pageInfo;
    }
    public List<Stall> zt_selStall() {
        return zt_stallMapper.selectStall();
    }

    @Override
    public List<Stall> getStallByUidAndManId(Integer uid, Integer manid) {
        return zt_stallMapper.getStallByUidAndManId(uid,manid);
    }

    @Override
    public Integer updateStall(Stall stall) {
        return zt_stallMapper.updateStall(stall);
    }

    @Override
    public List<Stall> getAllStall() {
        return zt_stallMapper.selectStallAll(null,null);
    }

    @Override
    public Integer addStall(Stall stall) {
        return zt_stallMapper.addStall(stall);
    }

    @Override
    public PageInfo<Stall> getStallByUid(Integer uid, Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<Stall> stallList = zt_stallMapper.getStallByUid(uid);
        PageInfo<Stall> pageInfo = new PageInfo<>(stallList);
        return pageInfo;
    }

    @Override
    public Integer updateStallImg(Integer stallId, String imgUrl) {
        return zt_stallMapper.updateStallImg(stallId,imgUrl);
    }

    @Override
    public List<Stall> getStallByManagementId(Integer managementId) {
        return zt_stallMapper.getStallByManagementId(managementId);
    }

    @Override
    public Stall zt_selStallById(Integer stall_id) {
        return zt_stallMapper.selStallById(stall_id);
    }

    @Override
    public List<Vehicle> zt_selVehicle(Integer vehicle_uid) {
        return zt_stallMapper.selVehicle(vehicle_uid);
    }

    @Override
    public int updateStall_stateAndOrder(Order1 order1) {
        int count;
        Integer order_stall_id = order1.getOrder_stall_id();
        Integer order_vehicle_id = order1.getOrder_vehicle_id();
        Vehicle vehicle = zt_stallMapper.selVehicle_code(order_vehicle_id);
        order1.setOrder_vehicle_code(vehicle.getVehicle_code());
        int i1 = zt_stallMapper.updateStall_state(order_stall_id);
        int i2 = zt_stallMapper.insertOrder1Start(order1);
        count = i1+i2;
        return count;
    }


}
